#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int jc[N];
int jc_1[N];
int qpow(int x,int p,int mod){
    int res = 1;
    while(p){
        if(p & 1){
            res = 1ll*res*x%mod;
        }
        x = 1ll*x*x%mod;
        p >>= 1;
    }
    return res;
}
int main(){
    int T;
    cin>>T;
    jc[0] = 1;
    while(T--){
        int n,m,q;
        cin>>n>>m>>q;
        for(int i = 1;i<=m;i++){
            jc[i] = 1ll*jc[i - 1]*i%q;
        }
        jc_1[m] = qpow(jc[m],q - 2,q);
        for(int i = m - 1;i >= 1;i--){
            jc_1[i] = 1ll*jc_1[i + 1]*(i + 1)%q;
        }
        jc_1[0] = 1;
        int res = 1;
        cout<<1<<' ';
        for(int i = n;i >= n - m + 1;i--){
            res = 1ll*res*i%q;
            cout<<1ll*res*jc_1[n - i + 1]%q<<' ';
        }
        cout<<'\n';
    }
}